package com.agou.app.admin.demo.ajax.action;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import com.agou.app.admin.demo.ajax.vo.AjaxDemoVo;
import com.agou.core.ss.SSException;
import com.agou.core.ss.SSTrace;
import com.agou.ssh.core.base.BaseAction;
import com.opensymphony.xwork2.Action;

public class AjaxDemoAction extends BaseAction {
	private static final long serialVersionUID = -6682641698351007257L;

	private static SSTrace ssTrace = SSTrace.getInstance(AjaxDemoAction.class);
	//输入参数
	private AjaxDemoVo ajaxDemoVo;// 值对象

	public AjaxDemoVo getAjaxDemoVo() {
		return ajaxDemoVo;
	}

	public void setAjaxDemoVo(AjaxDemoVo ajaxDemoVo) {
		this.ajaxDemoVo = ajaxDemoVo;
	}
	//输出参数
	private Map<String, Object> dataset = new HashMap<String, Object>();

	public Map<String, Object> getDataset() {
		return dataset;
	}

	public void setDataset(Map<String, Object> datamap) {
		this.dataset = datamap;
	}
	
	/**
	{
	 "ajaxDemoVo":{"password":"1111111","remark":"备注","userLoginId":"admin"},
	 "datamap":{"return_info":"完成注册","success":true},"user":"admin"
	}
	**/
	@SuppressWarnings("null")
	public String demo() throws SSException, SQLException, IOException {
		try {
			ssTrace.debug("demo", "开始ajax演示：#0", ajaxDemoVo);
			ssTrace.debug("demo", "开始ajax演示（JDBC）：#0", this.getSessionFactory());
			if(ajaxDemoVo.userLoginId.equals("aaa")){
				String  s = null;
				s.length();//模拟异常。进入错误
			}
			//datamap.put("success", true);
			dataset.put("return_info", "注册成功");
			dataset.put("return_info", "完成注册");
			return Action.SUCCESS;// 用户注册错误
		} catch (Throwable e) {
			e.printStackTrace();
			//datamap.put("success", false);
			dataset.put("return_info", "注册失败");
			dataset.put("return_info", "失败注册");
			return Action.SUCCESS;// 用户注册错误
		} finally {
		}
	}
}
